﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Xml;
using System.Xml.Serialization;

namespace SusyGame_Model
{
    [Serializable]   
    public class ArrowDefender : Defender
    {   
        public ArrowDefender(Texture2D texture, Texture2D weaponTexture, Vector2 position)
            : base(texture, weaponTexture, position)
        {
            this.damage = 10; // Asigna el daño
            this.price = 25;   // Asigna el costo inicial
            this.Tipo = 1;
            this.radius = 400; // Asigna el radio
        }

        public ArrowDefender()
        {
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            if (WeaponTimer >= 0.75f && target != null)
            {
                Weapon weapon = new Weapon(WeaponTexture, Vector2.Subtract(center, new Vector2(WeaponTexture.Width / 2)), rotation, 6, damage);

                WeaponList.Add(weapon);
                WeaponTimer = 0;
            }

            for (int i = 0; i < WeaponList.Count; i++)
            {
                Weapon weapon = WeaponList[i];

                weapon.SetRotation(rotation);
                weapon.Update(gameTime);

                if (!IsInRange(weapon.Center))
                    weapon.Kill();

                if (target != null && Vector2.Distance(weapon.Center, target.Center) < 12)
                {
                    target.CurrentHealth -= weapon.Damage;
                    weapon.Kill();
                }

                if (weapon.IsDead())
                {
                    WeaponList.Remove(weapon);
                    i--;
                }
            }
        }
    }
}
